package com.shen.JUC.Lock8;

import java.util.concurrent.TimeUnit;

public class Lock1 {
    /*锁的8个问题
    *1.两个同步方法谁先执行
    * 答：由于锁的存在，一次性只能调取一个同步方法，谁先拿到谁先执行，所以先执行方法sell，sell方法延时也还是继续执行sell
    * */

    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();
        new Thread(()->{
            try {
                phone.sell();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"A").start();
        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{phone.call();},"B").start();
    }
}

class Phone{
    public synchronized void sell() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
        System.out.println("sell message");
    }
    public synchronized void call(){
        System.out.println("call phone");
    }
}